package com.jason.system.controller;

import com.alibaba.fastjson.JSONObject;
import com.jason.system.common.ResultEntity;
import com.jason.system.common.util.Pager;
import com.jason.system.entity.SignForm;
import com.jason.system.service.RemarkService;
import com.jason.system.service.SignFormService;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author jie
 * @version 1.0
 * success come from self-discipline
 * @date 2021/4/7 20:49
 */
@RestController
@RequestMapping("/api/signForm")
@Api(value = "/signForm" ,tags = "签到信息接口")
public class SignFormController {

  private static final Logger logger = LoggerFactory.getLogger(SignFormController.class);

  @Autowired
  SignFormService signFormService;

  @Autowired
  RemarkService remarkService;


  @ApiOperation(value = "获取签到表信息",notes = "获取所有签到表信息")
  @ApiImplicitParams({
          @ApiImplicitParam(paramType = "query",name = "page", value = "页数",required = true,dataType = "Integer"),
          @ApiImplicitParam(paramType = "query",name = "size",value = "每页个数",required = true,dataType = "Integer")
  })
  @ApiResponses({
          @ApiResponse(code = 200 , message = "获取所有签到表信息成功"),
          @ApiResponse(code = 201, message = "获取所有签到表信息失败")
  })
  @GetMapping("/getAll")
  public JSONObject getAllSignForm(@RequestParam("size") Integer size , @RequestParam("page") Integer page){
    logger.info("==>>>SignFormController==>>>进行路径：/api/signForm/getAll.....");
    JSONObject jsonObject = new JSONObject();
    ResultEntity r = new ResultEntity();
    logger.info("==>>>SignFormController==>>>获取的signForms对象中...");
    Pager<SignForm> sighForms = signFormService.getAllSighForms(page,size);
    if (sighForms!=null){
      logger.info("===>>获取的signForms对象==>>>: {}",sighForms);
      r.setCode(200);
      r.setMessage("获取签到表信息成功");
      r.setData(sighForms);
    }else {
      r.setCode(201);
      r.setMessage("获取签到表信息失败");
    }
    jsonObject.put("result",r);
    return jsonObject;
  }

  @ApiOperation(value = "添加签到表信息",notes = "添加签到表信息")
  @ApiImplicitParams({
          @ApiImplicitParam(paramType = "body",name = "time",value = "日期",required = true,dataType = "Date"),
          @ApiImplicitParam(paramType = "body",name = "week",value = "星期",required = true,dataType = "Integer"),
          @ApiImplicitParam(paramType = "body",name = "frequency",value = "班次",required = true,dataType = "Integer"),
          @ApiImplicitParam(paramType = "body",name = "operators",value = "值班人员（stuId）,以逗号分割",required = true,dataType = "String"),
          @ApiImplicitParam(paramType = "body",name = "absenteeism",value = "值班人员（stuId）,以逗号分割",required = true,dataType = "String"),
          @ApiImplicitParam(paramType = "body",name = "machineRoomKey1",value = "机房钥匙1号",required = true,dataType = "Integer"),
          @ApiImplicitParam(paramType = "body",name = "machineRoomKey2",value = "机房钥匙2号",required = true,dataType = "Integer"),
          @ApiImplicitParam(paramType = "body",name = "dutyDoorKey",value = "值班门钥匙",required = true,dataType = "Integer"),
          @ApiImplicitParam(paramType = "body",name = "tools",value = "工具（以字符串形式储存tid,以逗号分割）",required = true,dataType = "String"),
          @ApiImplicitParam(paramType = "body",name = "unacceptedPlatForm",value = "后勤维修平台未受理数量",required = true,dataType = "Integer"),
          @ApiImplicitParam(paramType = "body",name = "unacceptedPortalSite",value = "门户网站报修未完工数量",required = true,dataType = "Integer"),
          @ApiImplicitParam(paramType = "body",name = "unacceptedCommunication",value = "电信运维平台未完工数量",required = true,dataType = "Integer"),
          @ApiImplicitParam(paramType = "body",name = "abnormalHostDevices",value = "主机异常设备数量",required = true,dataType = "Integer"),
          @ApiImplicitParam(paramType = "body",name = "abnormalHostNames",value = "异常设备名称（以逗号分割）",required = true,dataType = "String"),
          @ApiImplicitParam(paramType = "body",name = "signName",value = "填写人签字",required = true,dataType = "String"),
          @ApiImplicitParam(paramType = "body",name = "remarks",value = "交接特殊情况备注(储存remarkId,以逗号分割)",required = true,dataType = "String"),
          @ApiImplicitParam(paramType = "body",name = "successorId",value = "接班人（储存stuId）",required = true,dataType = "Integer")
  })
  @ApiResponses({
          @ApiResponse(code = 200 , message = "添加签到表信息成功"),
          @ApiResponse(code = 201, message = "添加签到表信息失败")
  })
  @PostMapping("/insert")
  public JSONObject insertSignForm(@RequestBody SignForm insertSignForm){
    logger.info("==>>>signFormController==>>>进行路径：/api/signForm/insert.....");
    JSONObject jsonObject = new JSONObject();
    ResultEntity r = new ResultEntity();
    try {
      logger.info("==>>>signFormController==>>>添加签到表信息中...");
      signFormService.insertSignForm(insertSignForm);
      logger.info("==>>>signFormController==>>>添加签到表信息完成...");
      r.setCode(200);
      r.setMessage("添加签到表信息成功");
    }catch (Exception e){
      logger.info("==>>>signFormController==>>>添加签到表信息失败:{}",e.getMessage());
      r.setCode(201);
      r.setMessage("添加签到表信息失败");
    }
    jsonObject.put("result",r);
    return jsonObject;
  }

  @ApiOperation(value = "更新签到表信息",notes = "更新签到表信息")
  @ApiImplicitParams({
          @ApiImplicitParam(paramType = "body",name = "time",value = "日期",required = true,dataType = "Date"),
          @ApiImplicitParam(paramType = "body",name = "week",value = "星期",required = true,dataType = "Integer"),
          @ApiImplicitParam(paramType = "body",name = "frequency",value = "班次",required = true,dataType = "Integer"),
          @ApiImplicitParam(paramType = "body",name = "operators",value = "值班人员（stuId）,以逗号分割",required = true,dataType = "String"),
          @ApiImplicitParam(paramType = "body",name = "absenteeism",value = "值班人员（stuId）,以逗号分割",required = true,dataType = "String"),
          @ApiImplicitParam(paramType = "body",name = "machineRoomKey1",value = "机房钥匙1号",required = true,dataType = "Integer"),
          @ApiImplicitParam(paramType = "body",name = "machineRoomKey2",value = "机房钥匙2号",required = true,dataType = "Integer"),
          @ApiImplicitParam(paramType = "body",name = "dutyDoorKey",value = "值班门钥匙",required = true,dataType = "Integer"),
          @ApiImplicitParam(paramType = "body",name = "tools",value = "工具（以字符串形式储存tid,以逗号分割）",required = true,dataType = "String"),
          @ApiImplicitParam(paramType = "body",name = "unacceptedPlatForm",value = "后勤维修平台未受理数量",required = true,dataType = "Integer"),
          @ApiImplicitParam(paramType = "body",name = "unacceptedPortalSite",value = "门户网站报修未完工数量",required = true,dataType = "Integer"),
          @ApiImplicitParam(paramType = "body",name = "unacceptedCommunication",value = "电信运维平台未完工数量",required = true,dataType = "Integer"),
          @ApiImplicitParam(paramType = "body",name = "abnormalHostDevices",value = "主机异常设备数量",required = true,dataType = "Integer"),
          @ApiImplicitParam(paramType = "body",name = "abnormalHostNames",value = "异常设备名称（以逗号分割）",required = true,dataType = "String"),
          @ApiImplicitParam(paramType = "body",name = "signName",value = "填写人签字",required = true,dataType = "String"),
          @ApiImplicitParam(paramType = "body",name = "remarks",value = "交接特殊情况备注(储存remarkId,以逗号分割)",required = true,dataType = "String"),
          @ApiImplicitParam(paramType = "body",name = "successorId",value = "接班人（储存stuId）",required = true,dataType = "Integer")
  })
  @ApiResponses({
          @ApiResponse(code = 200 , message = "更新签到表信息成功"),
          @ApiResponse(code = 201, message = "更新签到表信息失败")
  })
  @PostMapping("/update")
  public JSONObject updateSignForm(@RequestBody SignForm updateSignForm){
    logger.info("==>>>signFormController==>>>进行路径：/api/signForm/update.....");
    JSONObject jsonObject = new JSONObject();
    ResultEntity r = new ResultEntity();
    try {
      logger.info("==>>>signFormController==>>>更新签到表信息中...");
      signFormService.updateSignForm(updateSignForm);
      logger.info("==>>>signFormController==>>>更新签到表信息完成...");
      r.setCode(200);
      r.setMessage("更新签到表信息成功");
    }catch (Exception e){
      logger.info("==>>>signFormController==>>>更新签到表信息失败:{}",e.getMessage());
      r.setCode(201);
      r.setMessage("更新签到表信息失败");
    }
    jsonObject.put("result",r);
    return jsonObject;
  }


  @ApiOperation(value = "删除签到表信息",notes = "删除签到表信息")
  @ApiImplicitParam(paramType = "query",name = "sfId",value = "签到表id",required = true,dataType = "Integer")
  @ApiResponses({
          @ApiResponse(code = 200 , message = "删除签到表信息成功"),
          @ApiResponse(code = 201, message = "删除签到表信息失败")
  })
  @PostMapping("/delete")
  public JSONObject deleteSignForm(@RequestParam("sfId") Integer sfId){
    logger.info("==>>>signFormController==>>>进行路径：/api/signForm/delete.....");
    JSONObject jsonObject = new JSONObject();
    ResultEntity r = new ResultEntity();
    logger.info("==>>>signFormController==>>>删除签到表信息中...");
    boolean result = signFormService.deleteSignForm(sfId);
    if (result) {
      r.setCode(200);
      r.setMessage("删除签到表信息成功");
      logger.info("==>>>signFormController==>>>删除签到表信息完成...");
    }else {
      r.setCode(201);
      r.setMessage("删除签到表信息失败");
      logger.info("==>>>signFormController==>>>删除签到表信息失败...");
    }
    jsonObject.put("result",r);
    return jsonObject;
  }

  @ApiOperation(value = "批量删除签到表信息",notes = "批量删除签到表信息")
  @ApiImplicitParam(paramType = "query",name = "sfIds",value = "签到表ids,以逗号分割",required = true,dataType = "String")
  @ApiResponses({
          @ApiResponse(code = 200 , message = "批量删除签到表信息成功"),
          @ApiResponse(code = 201, message = "批量删除签到表信息失败")
  })
  @PostMapping("/deleteMore")
  public JSONObject deleteSignForm(@RequestParam("sfIds") String sfIds){
    logger.info("==>>>signFormController==>>>进行路径：/api/signForm/deleteMore.....");
    JSONObject jsonObject = new JSONObject();
    ResultEntity r = new ResultEntity();
    logger.info("==>>>signFormController==>>>批量删除签到表信息中...");
    boolean result = signFormService.deleteSignForms(sfIds);
    if (result) {
      r.setCode(200);
      r.setMessage("批量删除签到表信息成功");
      logger.info("==>>>signFormController==>>>批量删除签到表信息完成...");
    }else {
      r.setCode(201);
      r.setMessage("批量删除签到表信息失败");
      logger.info("==>>>signFormController==>>>批量删除签到表信息失败...");
    }
    jsonObject.put("result",r);
    return jsonObject;
  }

}
